home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / TabCell / TabSelectionCell.m < prev   
Text File  |  1994-08-04  |  7KB  |  272 lines

  1. #import "TabSelectionCell.h"
  2.  
  3. #define    TAB_IMAGE_WIDTH        14.0
  4. #define    TAB_IMAGE_HEIGHT    17.0
  5. #define    HALF_TAB_WIDTH        7.0
  6.  
  7. @implementation TabSelectionCell
  8.  
  9. /* Methods overridden from superclass */
  10. - initTextCell:(const char *)aString
  11. {
  12.     /* Do the superclass' initTextCell: method */
  13.     [super initTextCell:aString];
  14.     
  15.     /* Finish the initializing process */
  16.     [self finishInitializing];
  17.  
  18.     return self;
  19. }
  20.  
  21. - awake
  22. {
  23.     /* Do the superclass' awake method */
  24.     [super awake];
  25.     
  26.     /* Finish the initializing process */
  27.     [self finishInitializing];
  28.  
  29.     return self;
  30. }
  31.  
  32. - setFont:fontObj
  33. {
  34.     /* Do the superclass' init method */
  35.     [super setFont:fontObj];
  36.  
  37.     /* Grab the font information for the contents of the cell */
  38.     NXTextFontInfo(fontObj,&ascender,&descender,&lineHeight);
  39.     
  40.     return self;
  41. }    
  42.  
  43. - drawInside:(const NXRect *)cellFrame inView:controlView
  44. {
  45.     NXPoint    leftImageOrigin,rightImageOrigin;
  46.     NXRect    textFrame,lowerBezelFrame;
  47.     id        controlCellList = [controlView cellList];
  48.     int        ourIndex = [controlCellList indexOf:self];
  49.  
  50.     /* If there are no contents */
  51.     if (!contents)
  52.     {
  53.         /* Exit here! */
  54.         return self;
  55.     }
  56.  
  57.     /* Set the drawing to be totally opaque */
  58.     PSsetalpha(1.0);
  59.  
  60.     /* Set up the lowerBezelFrame that will be used for drawing the bezel at
  61.         our bottom */
  62.     NXSetRect(&lowerBezelFrame,
  63.                 cellFrame->origin.x + HALF_TAB_WIDTH,
  64.                 NX_MAXY(cellFrame) - 1.0,
  65.                 cellFrame->size.width,
  66.                 1.0);
  67.  
  68.     /* Set textFrame to cellFrame */
  69.     textFrame = *cellFrame;
  70.  
  71.     /* Set up the leftImageOrigin */
  72.     leftImageOrigin.x = NX_X(cellFrame);
  73.     leftImageOrigin.y = NX_MAXY(cellFrame);
  74.  
  75.     /* If ourIndex is 0 (we are the first cell) */
  76.     if (ourIndex == 0)
  77.     {
  78.         /* If we are selected */
  79.         if ([self isSelected])
  80.         {
  81.             /* Composite tabBeginSelectedImage to leftImageOrigin */
  82.             [tabBeginSelectedImage composite:NX_SOVER
  83.                                             toPoint:&leftImageOrigin];
  84.         }
  85.         else
  86.         {
  87.             /* Otherwise, composite tabBeginImage to leftImageOrigin */
  88.             [tabBeginImage composite:NX_SOVER toPoint:&leftImageOrigin];
  89.             
  90.             /* Subtract a HALF_TAB_WIDTH from lowerBezelFrame's x */
  91.             lowerBezelFrame.origin.x -= HALF_TAB_WIDTH;
  92.         }
  93.  
  94.         /* Add a TAB_IMAGE_WIDTH to textFrame's x */
  95.         textFrame.origin.x += TAB_IMAGE_WIDTH;
  96.  
  97.         /* Subtract a TAB_IMAGE_WIDTH plus HALF_TAB_WIDTH minus 1.0 from
  98.             textFrame's width */
  99.         textFrame.size.width -= TAB_IMAGE_WIDTH + HALF_TAB_WIDTH - 1.0;        
  100.     }
  101.     else
  102.     {
  103.         /* Subtract a HALF_TAB_WIDTH from leftImageOrigin's x */
  104.         leftImageOrigin.x -= HALF_TAB_WIDTH;
  105.         
  106.         /* If the cell to left of us is selected */
  107.         if ([[controlCellList objectAt:ourIndex-1] isSelected])
  108.         {
  109.             /* Composite tabBeginImage to leftImageOrigin */
  110.             [tabBeginImage composite:NX_SOVER toPoint:&leftImageOrigin];
  111.  
  112.             /* Composite tabEndSelectedImage to leftImageOrigin */
  113.             [tabEndSelectedImage composite:NX_SOVER toPoint:&leftImageOrigin];
  114.         }
  115.         else if ([self isSelected])
  116.         {
  117.             /* Otherwise, if we are selected */
  118.  
  119.             /* Composite tabEndImage to leftImageOrigin */
  120.             [tabEndImage composite:NX_SOVER toPoint:&leftImageOrigin];
  121.  
  122.             /* Composite tabBeginSelectedImage to leftImageOrigin */
  123.             [tabBeginSelectedImage composite:NX_SOVER
  124.                                             toPoint:&leftImageOrigin];
  125.         }
  126.         else
  127.         {
  128.             /* Composite tabBeginImage to leftImageOrigin */
  129.             [tabBeginImage composite:NX_SOVER toPoint:&leftImageOrigin];
  130.  
  131.             /* Composite tabEndImage to leftImageOrigin */
  132.             [tabEndImage composite:NX_SOVER toPoint:&leftImageOrigin];
  133.  
  134.             /* Subtract a HALF_TAB_WIDTH from lowerBezelFrame's x */
  135.             lowerBezelFrame.origin.x -= TAB_IMAGE_WIDTH;
  136.  
  137.             /* Add 1.0 to lowerBezelFrame's width */
  138.             lowerBezelFrame.size.width += 1.0;
  139.         }
  140.  
  141.         /* Add a HALF_TAB_WIDTH to textFrame's x */
  142.         textFrame.origin.x += HALF_TAB_WIDTH;
  143.  
  144.         /* Subtract a TAB_IMAGE_WIDTH minus 1.0 from textFrame's width */
  145.         textFrame.size.width -= TAB_IMAGE_WIDTH - 1.0;        
  146.     }
  147.  
  148.     /* If ourIndex is less than controlCellList's count minus 1 (we are not
  149.         the last cell) */
  150.     if (ourIndex < [controlCellList count]-1)
  151.     {
  152.         /* Draw the cell to the right of us */
  153.         [controlView drawCell:[controlCellList objectAt:ourIndex+1]];        
  154.     }
  155.     else
  156.     {
  157.         /* Set up the rightImageOrigin */
  158.         rightImageOrigin.x = NX_X(cellFrame) + NX_WIDTH(cellFrame)
  159.                                                             - TAB_IMAGE_WIDTH;
  160.         rightImageOrigin.y = NX_Y(cellFrame) + NX_HEIGHT(cellFrame);
  161.  
  162.         /* If we are selected */
  163.         if ([self isSelected])
  164.         {
  165.             /* Composite tabEndSelectedImage to rightImageOrigin */
  166.             [tabEndSelectedImage composite:NX_SOVER
  167.                                             toPoint:&rightImageOrigin];
  168.         }
  169.         else
  170.         {
  171.             /* Composite tabEndImage to rightImageOrigin */
  172.             [tabEndImage composite:NX_SOVER toPoint:&rightImageOrigin];
  173.         }
  174.  
  175.         /* Subtract a TAB_IMAGE_WIDTH from textFrame's width */
  176.         textFrame.size.width -= HALF_TAB_WIDTH;        
  177.         
  178.         /* Add a HALF_TAB_WIDTH to lowerBezelFrame's width */
  179.         lowerBezelFrame.size.width += HALF_TAB_WIDTH;
  180.     }
  181.  
  182.     /* Erase the cell */
  183.     
  184.     /* If we are selected */
  185.     if ([self isSelected])
  186.     {
  187.         /* Set our drawing color to NX_LTGRAY */        
  188.         PSsetgray(NX_LTGRAY);
  189.     }
  190.     else
  191.     {
  192.         PSsetgray(.5);
  193.     }
  194.     
  195.     /* Fill in textFrame */
  196.     NXRectFill(&textFrame);
  197.  
  198.     /* Now draw the upper bezel */
  199.     
  200.     /* Set our drawing color to NX_LTGRAY */        
  201.     PSsetgray(NX_LTGRAY);
  202.     
  203.     /* Set textFrame's height to 1.0 */
  204.     textFrame.size.height = 1.0;
  205.  
  206.     /* Fill in textFrame */
  207.     NXRectFill(&textFrame);
  208.  
  209.     /* Now draw the text */
  210.  
  211.     /* Set our drawing color to NX_BLACK */        
  212.     PSsetgray(NX_BLACK);
  213.     
  214.     /* Draw the cell's contents */
  215.     PSmoveto(NX_X(&textFrame),NX_Y(&textFrame)+lineHeight-descender+2.0);
  216.     PSshow(contents);
  217.  
  218.     /* If we are not selected */
  219.     if (![self isSelected])
  220.     {
  221.         /* Draw the lower bezel */
  222.  
  223.         /* Set our drawing color to NX_WHITE */        
  224.         PSsetgray(NX_WHITE);
  225.  
  226.         /* Fill in lowerBezelFrame */
  227.         NXRectFill(&lowerBezelFrame);
  228.     }
  229.  
  230.     return self;
  231. }
  232.  
  233. /* Other instance methods */
  234. - finishInitializing
  235. {
  236.     /* Get the "tabBegin" image */
  237.     if (!tabBeginImage)
  238.     {
  239.         tabBeginImage = [NXImage findImageNamed:"TabBegin"];
  240.     }
  241.  
  242.     /* Get the "tabEnd" image */
  243.     if (!tabEndImage)
  244.     {
  245.         tabEndImage = [NXImage findImageNamed:"TabEnd"];
  246.     }
  247.  
  248.     /* Get the "tabBeginSelected" image */
  249.     if (!tabBeginSelectedImage)
  250.     {
  251.         tabBeginSelectedImage = [NXImage findImageNamed:"TabBeginSelected"];
  252.     }
  253.  
  254.     /* Get the "tabEndSelected" image */
  255.     if (!tabEndSelectedImage)
  256.     {
  257.         tabEndSelectedImage = [NXImage findImageNamed:"TabEndSelected"];
  258.     }
  259.  
  260.     /* All text displayed will be in Helvetica, 12 point */
  261.     [self setFont:[Font newFont:"Helvetica" size:12.0]];
  262.  
  263.     return self;
  264. }
  265.  
  266. - (BOOL)isSelected
  267. {
  268.     /* Return YES if either one of these flags are on */
  269.     return (cFlags1.state || cFlags1.highlighted);
  270. }
  271.  
  272. @end